package com.yango.staService.controller;


import com.yango.commonutil.result.Result;
import com.yango.staService.service.StatisticsDailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author LiDingYin
 * @since 2021-08-05
 */
@Api(description = "网站统计日数据 前端控制器")
@RestController
@RequestMapping("/staService/statisticsDaily")
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService dailyService;

    //生成统计数据
    @ApiOperation(value = "生成统计数据")
    @PostMapping("/createStatisticsByDay/{day}")
    public Result createStatisticsByDay(@ApiParam(name = "day", value = "统计日期", required = true)
                                        @PathVariable String day) {
        //调用方法
        boolean falg = dailyService.createStatisticsByDay(day);
        if (falg) {
            return Result.ok().message("生成统计数据成功!");
        } else {
            return Result.error().message("生成统计数据失败!");
        }
    }

    //查询统计信息-图表显示
    @ApiOperation(value = "查询统计信息-图表显示")
    @GetMapping("/showChart/{type}/{begin}/{end}")
    public Result showChart(@ApiParam(name = "type", value = "统计字段", required = true)
                            @PathVariable String type,
                            @ApiParam(name = "begin", value = "开始时间", required = true)
                            @PathVariable String begin,
                            @ApiParam(name = "end", value = "结束时间", required = true)
                            @PathVariable String end) {
        Map<String, Object> map = dailyService.showChart(type, begin, end);
        return Result.ok().data(map);
    }

}

